import utils.array_utils as utils
# 桶排序


def bucket_sort(l):
    l2 = (max(l) + 1) * [0]
    print(l2)
    for i in l:
        l2[i] += 1
    print(l2)
    l = []
    for index, i in enumerate(l2):
        print(index, i)
        for j in range(i):
            l.append(index)
    print(l)


def bucket_sort2(l):
    # print(l2)
    mi = min(l)
    p = 0
    if mi < 0:
        p = mi
        l = [l[i] + abs(mi) for i in range(len(l))]
        # print(l)
    l2 = (max(l) + 1) * [0]
    for i in l:
        l2[i] += 1
    # print(l2)
    l=[]
    for index, i in enumerate(l2):
        # print(index, i)
        for j in range(i):
            l.append(index)
            print(l)
    if mi < 0:
        l = [l[i] - abs(mi) for i in range(len(l))]
    # print('l:',l)
    return l


def f(n):
    """
    将给定的整数n,从最大位逐个打印, 并存入列表返回
    :param n:
    :return:
    """
    l = len(str(n))
    nums = []
    for i in range(l):
        n2 = 10 ** (l - i - 1)
        n3 = n // n2 % 10
        nums.append(n3)
        print(n2, n3)
    return nums


if __name__ == '__main__':
    ll = [-3, -1, 2, 999, 3, 10]
    print(ll)
    print(bucket_sort2(ll))

    # print(utils.check_is_sorted(bucket_sort2))
    # print(f(197564))
